package com.集合.Collection___.Set_.HashSet__;

import com.extends01.A;

import java.util.HashSet;
import java.util.Objects;

@SuppressWarnings("all")
public class Exercise02 {
    public static void main(String[] args) {
        HashSet hashSet = new HashSet();
        hashSet.add(new Employee02("jeak",18,2004,11,1));
        hashSet.add(new Employee02("jeak",18,2004,11,1));
        hashSet.add(new Employee02("jeak",18,2004,11,1));
        hashSet.add(new Employee02("jeak",18,2004,11,1));
        System.out.println("hashSet = "+ hashSet);
    }
}

class Employee02 {
    String name;
    int age;
    MyDate birthday;

    public Employee02(String name, int age, int year,int month, int day) {
        this.name = name;
        this.age = age;
        birthday = new MyDate(year, month, day);
    }

    @Override
    public String toString() {
        return "name = " + name ;
    }

    @Override
    public boolean equals(Object o) {
        if (o == null || getClass() != o.getClass()) return false;
        Employee02 that = (Employee02) o;
        return age == that.age && Objects.equals(name, that.name)&&this.birthday.equals(that.birthday);
//        return age == that.age && Objects.equals(name, that.name) &&
//                Objects.equals(birthday.getYear(), that.birthday.getYear())&&
//                Objects.equals(birthday.getMonth(), that.birthday.getMonth())&&
//                Objects.equals(birthday.getDay(), that.birthday.getDay());
    }

    @Override
    public int hashCode() {
        return Objects.hash(name, age, birthday.getYear(), birthday.getMonth(), birthday.getDay());
    }
}


 class MyDate{
    private final int year;
    private final int month;
    private final int day;
    public MyDate(int year, int month, int day) {
        this.year = year;
        this.month = month;
        this.day = day;
    }

     public int getYear() {
         return year;
     }

     public int getMonth() {
         return month;
     }

     public int getDay() {
         return day;
     }

     @Override
     public String toString() {
         return year + "  " + month + "  " + day + "}\n";
     }

     @Override
     public boolean equals(Object o) {
         if (o == null || getClass() != o.getClass()) return false;
         MyDate myDate = (MyDate) o;
         return year == myDate.year && month == myDate.month && day == myDate.day;
     }


 }